#include "gb28181_interface.h"
#include "gb28181_manager.h"
#include <memory>
#include <mutex>

namespace El {
namespace GB28181 {

class GB28181ServiceImpl : public IGB28181Service {
public:
    GB28181ServiceImpl() : manager_(GB28181Manager::GetInstance()) {
        manager_.Initialize();
    }
    
    ~GB28181ServiceImpl() {
        manager_.Shutdown();
    }
    
    bool Start() override {
        return manager_.StartServices();
    }
    
    void Stop() override {
        manager_.StopServices();
    }
    
    bool IsRunning() const override {
        return manager_.IsServiceRunning();
    }
    
    std::string GetConfig() const override {
        return manager_.GetConfig();
    }
    
    DeviceStatus GetDeviceStatus(int server_index = 0) const override {
        return manager_.GetDeviceStatus(server_index);
    }
    
    std::string GetStatusString(DeviceStatus status) const override {
        return manager_.GetStatusString(status);
    }
    
    void SetStatusCallback(StatusCallback callback) override {
        (void)callback;  // 标记参数为未使用
        // TODO: 实现状态回调设置
        // manager_.SetStatusCallback(callback);
    }
    
private:
    GB28181Manager& manager_;
};

class GB28181FactoryImpl : public IGB28181Factory {
public:
    std::unique_ptr<IGB28181Service> CreateService() override {
        return std::make_unique<GB28181ServiceImpl>();
    }
};

std::unique_ptr<IGB28181Factory> CreateGB28181Factory() {
    return std::make_unique<GB28181FactoryImpl>();
}

} // namespace GB28181
} // namespace El